package com.haitai.solr.config;

import com.haitai.solr.resp.RespData;
import com.haitai.solr.resp.StateCodeDesc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
    /**
     * 处理自定义异常，其他未处理的异常，按系统异常处理
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public RespData<String> exceptionHandler(Exception e){
        logger.error("系统错误：", e);
        return RespData.failRsp(StateCodeDesc.SYSTEM_ERROR.getCode(), StateCodeDesc.SYSTEM_ERROR.getCodeDesc(), false);
    }


}
